package org.mili.ticketeer.dto;

import java.util.HashMap;
import java.util.Map;

public class State extends Identifieable implements Archivable {

    public static enum Fields implements Field {
        TOKEN,
        TITLE;
    }

    public static final String TABLE = "state";

    private String token;
    private String title;

    @Override
    public Map<Field, Object> valueMap() {
        Map<Field, Object> map = super.valueMap();
        map.put(Fields.TOKEN, token);
        map.put(Fields.TITLE, title);
        return map;
    }

    @Override
    public Map<Field, Object> valueMapWithoutId() {
        Map<Field, Object> map = new HashMap<>(valueMap());
        map.remove(Identifieable.Fields.ID);
        return map;
    }

    @Override
    public Map<Field, Object> getUniqueFields() {
        return valueMapWithoutId();
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        State state = (State) o;

        if (title != null ? !title.equals(state.title) : state.title != null) return false;
        if (token != null ? !token.equals(state.token) : state.token != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = token != null ? token.hashCode() : 0;
        result = 31 * result + (title != null ? title.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "State{" +
                "token='" + token + '\'' +
                ", title='" + title + '\'' +
                '}';
    }
}
